package chapter5.homework.GeometryCalc;

import java.util.Scanner;

public class Main {
    static boolean welcomed=false;
    static boolean choiceSuccess =false;
    static final String[] prompt={"圆","矩形","三角形","退出"};
    static final int CIRCLE=1,RECTANGLE=2,TRIANGLE=3,EXIT=4;
    public static void main(String[] args) {
        Circle circle=null;
        Rectangle rectangle=null;
        Triangle triangle=new Triangle();
        Scanner scanner=new Scanner(System.in);
        int choice;

        do{
            choice=show();
            switch (choice) {
                case EXIT:
                    Main.count();
                    break;
                case TRIANGLE:
                    triangle.calc();
                    break;
                case RECTANGLE:
                    Rectangle.calc();
                    break;
                case CIRCLE:
                    Circle.calc();
                    break;
            }
        }while (choice!=4);
    }
    static int show(){
        int choice;
        int i;

        Scanner sc=new Scanner(System.in);

        if(welcomed) {
            if(choiceSuccess){
                System.out.println();
            }
            else{
                System.out.println("输入无效，请再试一次");
            }
        }
        else {
            welcomed = true;
            System.out.println("欢迎使用几何计算器");
        }
        System.out.println("请选择以下一项");
        for(i=0;i< prompt.length;i++){
            System.out.print((i+1)+".\t"+prompt[i]+"\t");
        }
        System.out.println();
        choice=sc.nextInt();
        if(choice<=4 && choice >0) {
            choiceSuccess=true;
            return choice;
        }
        else{
            choiceSuccess =false;
            return show();
        }
    }
    static void count(){
        System.out.println("本次使用共计算了：");
        System.out.println(Circle.getCounter()+"\t个圆");
        System.out.println(Rectangle.getCounter()+"\t个矩形");
        System.out.println(Triangle.getCounter()+"\t个三角形");
        System.out.println("欢迎下次使用！");
    }
}

